const webpack = require('webpack');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const dirVars = require('./webpack-config/base/dir-vars.config.js'); // 与业务代码共用同一份路径的配置表
const CopyWebpackPlugin = require('copy-webpack-plugin');
module.exports = {
    output: {
        path: dirVars.dllDir,
        filename: '[name].js',
        library: '[name]', // 当前Dll的所有内容都会存放在这个参数指定变量名的一个全局变量下，注意与DllPlugin的name参数保持一致
    },
    entry: {
        /*
          指定需要打包的js模块
          或是css/less/图片/字体文件等资源，但注意要在module参数配置好相应的loader
        */
        dll: [
            'jquery',
            'avalon2',
            'layer/layer.js', 'layer/skin/default/layer.css',
            'router/mmRouter.js'
        ],
    },
    plugins: [
        new webpack.DllPlugin({
            path: 'manifest.json', // 本Dll文件中各模块的索引，供DllReferencePlugin读取使用
            name: '[name]', // 当前Dll的所有内容都会存放在这个参数指定变量名的一个全局变量下，注意与参数output.library保持一致
            context: dirVars.staticRootDir, // 指定一个路径作为上下文环境，需要与DllReferencePlugin的context参数保持一致，建议统一设置为项目根目录
        }),
        new ExtractTextPlugin('[name].css'), // 打包css/less的时候会用到ExtractTextPlugin
        new webpack.optimize.UglifyJsPlugin({
            compress: {
                warnings: false,
            },
        }),
        /*复制ueditor文件夹*/
        new CopyWebpackPlugin([
            { from: dirVars.vendorDir+'/ueditor_1443', to: 'ueditor_1443' },
        ])
    ],
    module: {
        rules: [{
            test: /\.css$/,
            use: ExtractTextPlugin.extract({
                fallback: "style-loader",
                use: "css-loader",
            })
        }, {
            test: /\.(png|jpg|gif)$/,
            include: dirVars.vendorRootDir,
            use: {
                loader: 'file-loader',
                options: {
                    //limit: 8192,
                    name: 'images/[name].[ext]'
                }
            }
        }, {
            test: /\.html$/,
            use: {
                loader: 'html-loader'
            }
        }]
    },
    resolve: require('./webpack-config/resolve.config.js'), // 沿用业务代码的resolve配置
};